﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SaleOnlineSystem
{
    public partial class VendorSearch : System.Web.UI.Page
    {
        public static string vendorID;
        public static int sizePage;
        public static int currentPage;
        public string catID;
        public string catName;
        public static DataTable dt;
        public static int AllCat;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (SaleOnlineSystem.Controls.SortProduct.column == null) SaleOnlineSystem.Controls.SortProduct.column = "Product_Name";
                if (SaleOnlineSystem.Controls.SortProduct.sort == null) SaleOnlineSystem.Controls.SortProduct.sort = "DESC";
                sizePage = Convert.ToInt32(ConfigurationManager.AppSettings["sizepage"].ToString());

                if (Request.QueryString["currentPage"] != null)
                {
                   

                    if (Request.QueryString["vendorID"] != null)
                        vendorID = (Request.QueryString["vendorID"].ToString());
                    else
                        Response.Redirect("Error.aspx");

                    currentPage = Convert.ToInt32(Request.QueryString["currentPage"].ToString());
                    dt = BOL.ProductManager.Instance.GetListProductsPaging("tbl_Product", "searchvendor", currentPage, sizePage, vendorID,
                                                                            "Vendor_ID", SaleOnlineSystem.Controls.SortProduct.sort, SaleOnlineSystem.Controls.SortProduct.column);
                }


                else
                {
                   

                    if (Request.QueryString["vendorID"] != null)
                        vendorID = (Request.QueryString["vendorID"].ToString());
                    else
                        Response.Redirect("Error.aspx");


                    dt = BOL.ProductManager.Instance.GetListProductsPaging("tbl_Product", "searchvendor", 1, sizePage, vendorID,
                                                                             "Vendor_ID", SaleOnlineSystem.Controls.SortProduct.sort, SaleOnlineSystem.Controls.SortProduct.column);
                    currentPage = 1;
                }


                // VIet stored dem so san pham co catID 
                catName = "Tìm kiếm nha san xuat ";
                AllCat = Convert.ToInt32(DAL.DCollector.DBCollector.Instance.StoredProcedureSelectWhereByID("tbl_Product", "Vendor_ID", vendorID, "selectcountwhere").Rows[0]["count"].ToString());
            }

        }
    }
}